﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using DragDraw.Util;

namespace DragDraw
{
    public partial class ToolPanelControl : UserControl, ITaskBar
    {
        private FriendControl m_friendControl;
        private ToolControl m_toolControl;
        private SettingControl m_settingControl;
        //private SysMessageControl m_sysMessageControl;
        private LoginControl m_loginControl;
        private bool m_isLogin;

        public ToolPanelControl()
        {
            InitializeComponent();
            m_friendControl = new FriendControl();
            m_toolControl = new ToolControl();
            m_settingControl = new SettingControl();
            //m_sysMessageControl = new SysMessageControl();
            m_loginControl = new LoginControl();

            btnMySpace.Visibility = Visibility.Collapsed;
            btnFriend.Visibility = Visibility.Collapsed;
            btnTools.Visibility = Visibility.Collapsed;
            //btnMessage.Visibility = Visibility.Collapsed;
            btnSetting.Visibility = Visibility.Collapsed;
        }

        public void SetStatus(int status)
        {
            switch (status)
            {
                case SpaceManager.STATUS_INIT:
                    btnMySpace.Visibility = Visibility.Collapsed;
                    btnFriend.Visibility = Visibility.Collapsed;
                    btnTools.Visibility = Visibility.Collapsed;
                    //btnMessage.Visibility = Visibility.Collapsed;
                    btnSetting.Visibility = Visibility.Collapsed;
                    btnLogin.Content = "我要登录";
                    m_isLogin = false;
                    break;
                case SpaceManager.STATUS_MYSPACE:
                    btnLogin.Content = "退出";
                    btnMySpace.Visibility = Visibility.Collapsed;
                    btnFriend.Visibility = Visibility.Visible;
                    btnTools.Visibility = Visibility.Visible;
                    //btnMessage.Visibility = Visibility.Visible;
                    btnSetting.Visibility = Visibility.Visible;
                    m_isLogin = true;
                    break;
                case SpaceManager.STATUS_NOT_MYSPACE:
                    btnLogin.Content = "退出";
                    btnMySpace.Visibility = Visibility.Visible;
                    btnFriend.Visibility = Visibility.Visible;
                    btnTools.Visibility = Visibility.Collapsed;
                    //btnMessage.Visibility = Visibility.Visible;
                    btnSetting.Visibility = Visibility.Collapsed;
                    m_isLogin = true;
                    break;
                default:
                    ErrorManager.Instance.ShowDebugMessage("SpaceManager::SetStatus Fail");
                    break;
            }
        }

        public void ShowMessage(string message)
        {
        }

        private void btnFriend_Click(object sender, RoutedEventArgs e)
        {
            m_friendControl.Init();
            OperationManager.Instance.
                CurrentSpaceManager.ShowModalDialog(m_friendControl, "好友管理");
        }

        private void btnTools_Click(object sender, RoutedEventArgs e)
        {
            m_toolControl.Init();
            OperationManager.Instance.
                CurrentSpaceManager.ShowModalDialog(m_toolControl, "小工具管理");
        }

        private void btnSetting_Click(object sender, RoutedEventArgs e)
        {
            m_settingControl.Init();
            OperationManager.Instance.
                CurrentSpaceManager.ShowModalDialog(m_settingControl, "我的设置");
        }
        /*
        private void btnMessage_Click(object sender, RoutedEventArgs e)
        {
            m_sysMessageControl.Init();
            OperationManager.Instance.
                CurrentSpaceManager.ShowModalDialog(m_sysMessageControl, "我的信息");
        }*/

        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            if (m_isLogin == false)
            {
                m_loginControl.Init();
                OperationManager.Instance.
                    CurrentSpaceManager.ShowModalDialog(m_loginControl, "登陆");
            }
            else
            {
                OperationManager.Instance.Logout();
            }
        }

        private void btnMySpace_Click(object sender, RoutedEventArgs e)
        {
            if(OperationManager.Instance.IsInMySpace == false)
                OperationManager.Instance.
                    EnterSpace(OperationManager.Instance.MyUserInfo.UserID);
        }

        private void BtnFullScreen_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Interop.Content contentObj = App.Current.Host.Content;
            contentObj.IsFullScreen = !contentObj.IsFullScreen;
        }
    }
}
